// pages/find/activity/detail.js
const config = getApp().globalData.config
const T = getApp().globalData.T
let token = ''
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: -1,
    list: [],
    page: 1,
    size: 10,
    isLoaded: false,
    isFirstTip: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.id = options.id;
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    token = getApp().globalData.token;
    this.getDetail();
  },

  getDetail() {
    T.req({
      loadTitle: '加载中...',
      url: config.api + 'forum/topic/activity/list',
      method: 'GET',
      data: {
        token: token,
        topicId: this.data.id,
        page: this.data.page,
        size: this.data.size
      },
      success: (res) => {
        if (res.rowCount == this.data.list.length) {
          this.data.isLoaded = true;
          return;
        }
        let tem01 = res.list.slice(0, 1)[0].subList;
        let tem02 = res.list.slice(1);
        this.setData({
          listTitle: tem01,
          list: this.data.list.concat(tem02)
        })
        console.log(this.data.list)
      }
    })
  },

  onReachBottom: function () {
    if (this.data.isLoaded) {
      if (this.data.isFirstTip) {
        this.toast('已加载完全部数据了');
      }
      this.data.isFirstTip = false;
      return;
    }
    this.data.page += 1;
    this.getDetail();
  }
})